home *** CD-ROM | disk | FTP | other *** search
- Path: mudskipper.cac.psu.edu!user
- From: fcusack@tdx.org (frank.)
- Newsgroups: comp.lang.c++
- Subject: Re: const wasting space and slower?
- Date: Mon, 19 Feb 1996 07:35:29 -0400
- Organization: Psychic Enemies Network
- Message-ID: <fcusack-1902960735290001@mudskipper.cac.psu.edu>
- References: <312814DB.399F@iastate.edu>
- NNTP-Posting-Host: mudskipper.cac.psu.edu
-
- In article <312814DB.399F@iastate.edu>, Steve Lee <sjlee@iastate.edu> wrote:
-
- [...]
- >
- > When you declare something like this:
- >
- > const int MAX_FILES = 20;
- >
- > doesn't the compiler reserve global, read-only memory for this
- variable? Or does it just replace
-
- It may reserve space. compile with debugging symbols on, you will see
- references to your variable name.
-
- > instances in the source code where MAX_FILES is found and replaces it
- with 20, similar to a
- > preprocessor, but with typechecking?
-
- Again, that probably depends on compiler switches. I'm sure that with
- optimization, you'll lose the variable, since it's a constant. You'll
- still retain typechecking. Why don't you check with your compiler?
-
- > Also, if the compiler does place it in memory, do
- > instructions then reference the memory, instead of immediate addressing mode?
- >
- > If this is so, I think it wastes space (storage of constants) and is
- slower (direct addressing
- > mode vs. immediate addressing mode).
- >
-
- yes, it probably does, but it vastly helps the write-test-debug process.
- When you are thoroughly debugged, you can optimize it away.
- ~Frank
- -- I am Pentium of Borg. Division is futile. You will be approximated. --
- -- If you build it, they will come --> http://www.tdx.org/~fcusack/ --
- -- PGP key fingerprint: 01 C0 C0 B9 CC 78 67 0F 3F 64 80 65 8B 0F F9 EA --
-